//package com.fanghuaman.gateway.filter;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.util.MultiValueMap;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
///**
// * @author shiminghui
// * @date 2025/2/5 14:05
// * @description: 解决跨域问题
// */
//@Component
//@Slf4j
//public class CorsFilter implements GlobalFilter, Ordered {
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        log.info("进入跨域过滤器");
//        ServerHttpResponse response = exchange.getResponse();
//        HttpHeaders headers = response.getHeaders();
//        headers.add("Access-Control-Allow-Origin", "*");
//        headers.add("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
//        headers.add("Access-Control-Allow-Headers", "*");
//
//
//        ServerHttpRequest request = exchange.getRequest();
//        if (request.getMethod().matches("OPTIONS")) {
//            return response.setComplete();
//        }
//
//        log.info("请求路径：{}", request.getURI());
//        MultiValueMap<String, String> queryParams = request.getQueryParams();
//        for (String key : queryParams.keySet()) {
//            log.info("{}:{}", key, queryParams.get(key));
//        }
//        log.info("{}", response.getHeaders());
//
//        return chain.filter(exchange);
//    }
//
//    @Override
//    public int getOrder() {
//        return Integer.MIN_VALUE;
//    }
//}
